首页 \ 问答 \ 使用BeautifulSoup获取属性值(Getting attribute's value using BeautifulSoup)

使用BeautifulSoup获取属性值(Getting attribute's value using BeautifulSoup)

我正在编写一个python脚本,它将在从网页解析后提取脚本位置。 可以说有两种情况:

<script type="text/javascript" src="http://example.com/something.js"></script>

<script>some JS</script>

我可以从第二个场景中获得JS,也就是当JS写在标签中时。

但有没有办法,我可以从第一个场景中获得src的值(即提取脚本内的src标记的所有值,例如http://example.com/something.js

这是我的代码

#!/usr/bin/python

import requests 
from bs4 import BeautifulSoup

r  = requests.get("http://rediff.com/")
data = r.text
soup = BeautifulSoup(data)
for n in soup.find_all('script'):
    print n 

输出 :一些JS

需要输出http//example.com/something.js


I'm writing a python script which will extract the script locations after parsing from a webpage. Lets say there are two scenarios :

<script type="text/javascript" src="http://example.com/something.js"></script>

and

<script>some JS</script>

I'm able to get the JS from the second scenario, that is when the JS is written within the tags.

But is there any way, I could get the value of src from the first scenario (i.e extracting all the values of src tags within script such as http://example.com/something.js)

Here's my code

#!/usr/bin/python

import requests 
from bs4 import BeautifulSoup

r  = requests.get("http://rediff.com/")
data = r.text
soup = BeautifulSoup(data)
for n in soup.find_all('script'):
    print n 

Output : Some JS

Output Needed : http://example.com/something.js


原文:https://stackoverflow.com/questions/18733023
更新时间:2023-02-16 18:02

最满意答案

FIND_PACKAGECOMPONENTS部分仅搜索已编译的库。 它无法检查构成Boost主要部分的只包含头文件的库。 只有少数库需要链接(主要是那些执行特定平台的东西的链接库)。

在你的例子中,只有threadsignals (与只有header的signals2相反), systemprogram_options需要事先建立,然后与你的程序链接。 其余的,包含相关的头文件就足够了。

因此,将${Boost_INCLUDE_DIRS}添加到目标的include目录就足够了。

请参阅这里查看这些库的库列表哪些boost库只有标头?


The COMPONENTS part of FIND_PACKAGE only searches for compiled libraries. It is not able to check for the header-only libraries that comprise a major part of Boost. There are only a few libraries that require linking (mostly those that perform platform-specific things).

From your examples, only thread, signals (in contrast to signals2 which is header-only), system and program_options need to be build beforehand and then linked with your program. For the rest, it is sufficient to include the relevant header files .

Thus, it is sufficient to add ${Boost_INCLUDE_DIRS} to the include directories of your target.

See here for a list of libraries of these libraries Which boost libraries are header-only?

相关问答

更多
  • FIND_PACKAGE的COMPONENTS部分仅搜索已编译的库。 它无法检查构成Boost主要部分的只包含头文件的库。 只有少数库需要链接(主要是那些执行特定平台的东西的链接库)。 在你的例子中,只有thread , signals (与只有header的signals2相反), system和program_options需要事先建立,然后与你的程序链接。 其余的,包含相关的头文件就足够了。 因此,将${Boost_INCLUDE_DIRS}添加到目标的include目录就足够了。 请参阅这里查看这些 ...
  • 在您的调试输出中,它看起来像Boost_USE_STATIC_LIBS未设置,但您正在寻找静态提升库。 尝试再次运行CMake,但将-DBoost_USE_STATIC_LIBS=ON添加到命令中。 实际上,您的CMakeLists.txt将其包含在另一个变量USE_STATIC_BOOST 。 将其设置为ON应该具有相同的效果。 In your debug output, it looks like Boost_USE_STATIC_LIBS is unset, but yet you're lookin ...
  • 以下是我必须做的事情,以使一切按预期工作: 从Visual Studio提示符 :使用以下命令重新编译boost: .\b2 --prefix=C:\boost toolset=gcc -j4 link=shared threading=multi --ignore-python --ignore-mpi --layout=tagged layout=tagged导致boost使libboost_system-mt.dll形式的库只表示它是多线程的。 它删除了之前导致问题的名称的无关部分。 从MinGW s ...
  • Boost.Optional是一个头只有库: 请参阅http://www.boost.org/doc/libs/1_60_0/libs/optional/doc/html/index.html find_package中的COMPONENTS仅适用于构建的库。 所以,你只需要写: find_package(Boost 1.58.0 REQUIRED) 看到类似的链接: CMake Boost 1.59.0几何 Boost.Optional is a head only libraries: see htt ...
  • 最后,我自己找到了解决方案。 问题确实是Boost::Python没有正确构建。 我完全不知道它是一个错误还是我自己的错,但在我的情况下,编辑Boost Build's user-config.jam使用python3.5是不够的:运行构建脚本导致libboost_python3.so ,但内部python2 .7使用翻译是出于我不知道的原因。 所以,我所做的是启动Boost初始引导为./bootstrap.sh --with-python=/usr/bin/python3.5m ,即指向所需解释器的绝对路 ...
  • 我猜你的编译库不在你的BOOST_ROOT / lib /文件夹中。 在这种情况下,您需要设置您的lib文件夹目录路径。 set(BOOST_LIBRARYDIR ${BOOST_ROOT}/stage/lib/) 要么 set(BOOST_LIBRARYDIR path/to/your/lib/folder) I guess your compiled libraries is not in your BOOST_ROOT/lib/ folder. In this case, you need to ...
  • 没关系,事实证明安装libboost-program-options-dev会建立链接。 Nevermind, turns out installing libboost-program-options-dev makes the link.
  • 检查正在使用的FindBoost.cmake脚本。 根据您使用的CMake版本,此版本的Boost可能无法处理。 库之间的依赖关系取决于发现的Boost版本。 例如,GitHub上 CMake源代码的最新版本处理版本1.63。 我遇到了CMake v3.6.2的问题,它无法处理它。 关于MSVC的版本不匹配,我不知道,对不起。 I compiled boost, and am compiling the linking application with the same toolset. Therefore ...
  • 您必须设置#define BOOST_LOG_DYN_LINK 1 ,这可以使用add_definitions(-DBOOST_LOG_DYN_LINK=1)使用cmake完成。 You have to set #define BOOST_LOG_DYN_LINK 1, this can be done with cmake using add_definitions(-DBOOST_LOG_DYN_LINK=1).
  • 此stackoverflow答案建议在cmake命令行上添加-DBoost_NO_BOOST_CMAKE=ON 。 这似乎是由于某些CMake版本与某些Boost版本不兼容的事实。 我同意Fraser的用户说的话。 这些线条没有意义 set(Boost_INCLUDE_DIR /software/apps/boost/1.55.0/build06/include) set(Boost_LIBRARY_DIR /software/apps/boost/1.55.0/build06/lib) 因为这些变量被 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)