使用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
最满意答案
FIND_PACKAGE
的COMPONENTS
部分仅搜索已编译的库。 它无法检查构成Boost主要部分的只包含头文件的库。 只有少数库需要链接(主要是那些执行特定平台的东西的链接库)。在你的例子中,只有
thread
,signals
(与只有header的signals2
相反),system
和program_options
需要事先建立,然后与你的程序链接。 其余的,包含相关的头文件就足够了。因此,将
${Boost_INCLUDE_DIRS}
添加到目标的include目录就足够了。请参阅这里查看这些库的库列表哪些boost库只有标头?
The
COMPONENTS
part ofFIND_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 tosignals2
which is header-only),system
andprogram_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 ...
-
Windows:Boost和CMake(Windows: Boost and CMake)[2022-11-22]
以下是我必须做的事情,以使一切按预期工作: 从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 ...
-
CMake Boost链接问题(CMake Boost linking problems)[2022-08-06]
最后,我自己找到了解决方案。 问题确实是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 ...
-
CMake无法在Debian上找到boost_program_options(CMake cannot find boost_program_options on Debian)[2022-03-11]
没关系,事实证明安装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) 因为这些变量被 ...