Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 网页抓取:全部阅读href_Python_Regex_Urllib - Fatal编程技术网

Python 网页抓取:全部阅读href

Python 网页抓取:全部阅读href,python,regex,urllib,Python,Regex,Urllib,我编写了一个小脚本,用python读取网页上的所有HREF。 但它有一个问题。例如,它不读取href=“pages.php?ef=fa&page=n\u fullstory.php&NewsIDn=1648” 代码: 有人能帮我吗?谢谢。使用BEautifulSoup和静态网站请求。这是一个伟大的网页抓取模块,使用代码,您可以很容易地获得href标签内的值。希望能有帮助 import requests from bs4 import BeautifulSoup url = 'whatever

我编写了一个小脚本,用python读取网页上的所有HREF。 但它有一个问题。例如,它不读取
href=“pages.php?ef=fa&page=n\u fullstory.php&NewsIDn=1648”

代码:


有人能帮我吗?谢谢。

使用BEautifulSoup和静态网站请求。这是一个伟大的网页抓取模块,使用代码,您可以很容易地获得href标签内的值。希望能有帮助

import requests
from bs4 import BeautifulSoup

url = 'whatever url you want to parse'

result = requests.get(url)

soup = BeautifulSoup(result.content,'html.parser')

for a in soup.find_all('a',href=True):
    print "Found the URL:", a['href']

一般建议:不要用正则表达式解析HTML。虽然您的特定案例可以实现,但如果您需要更多,它会很快变得非常混乱。使用适当的解析库。退房或退房。甚至可能。
import requests
from bs4 import BeautifulSoup

url = 'whatever url you want to parse'

result = requests.get(url)

soup = BeautifulSoup(result.content,'html.parser')

for a in soup.find_all('a',href=True):
    print "Found the URL:", a['href']