Python WebScraper未更新

Python WebScraper未更新,python,web-scraping,Python,Web Scraping,大家好,我正在创建一个简单的网络刮板,在搜索隐私后,它会记录cnet标题中显示的相关文章和日期。正如我的代码中所示,它正在使用链接来提取数据,但我遇到了一个问题。不管我添加到url代码末尾的页码是多少,它只是在抓取第一页。我用其他URL测试过它,它提取了不同的数据,所以我不明白为什么当我更改URL末尾的页码时,它没有显示与该页面相关的特定数据 如果可能的话,我正在尝试让它从所有页面中提取数据,但现在我正在尝试让它与至少一个不同的页面一起工作,而不是在搜索“隐私”时返回的主页面 下面是python

大家好,我正在创建一个简单的网络刮板,在搜索隐私后,它会记录cnet标题中显示的相关文章和日期。正如我的代码中所示,它正在使用链接来提取数据,但我遇到了一个问题。不管我添加到url代码末尾的页码是多少,它只是在抓取第一页。我用其他URL测试过它,它提取了不同的数据,所以我不明白为什么当我更改URL末尾的页码时,它没有显示与该页面相关的特定数据

如果可能的话,我正在尝试让它从所有页面中提取数据,但现在我正在尝试让它与至少一个不同的页面一起工作,而不是在搜索“隐私”时返回的主页面

下面是python代码

import urllib.request,re,webbrowser

##import MySQLdb
import cgi




##getUrl =
##getDate =
##getHeadline =
##
##cursor.execute(SQL)

def searchurl(url):

    page=urllib.request.urlopen(url)
    urls=page.read().decode(errors='replace')
    page.close()
    print("Searching:",url)
    ##get headers

    head = re.findall('(?<=<h3>).+?(?=</h3>)',urls)
    ##get links
    link = re.findall('(?<= <a href="/).+?\S+?(?=">)',urls,re.DOTALL)


    ##get date
    date = re.findall('(?<= <span class="assetTime">).+?(?=</span>)',urls)




    link.pop(0)
    link.pop(0)
    link.pop(0)
    link.pop(-1)
    link.pop(-1)
    for item in link:
        print(item)
    print("Header")
    for item in head:
        print(item)








url = "https://www.cnet.com/search/?query=privacy&page=3"
searchurl(url)

非常感谢您的帮助。

您可以通过浏览器直接导航到正确的页面,确认上面的URL不会重定向到正确的页面<代码>https://www.cnet.com/search/?query=privacy&page=6在浏览器中,您将进入第1页

查看页面选择器等。您可以看到分页通过以下方式工作:

(例如,您可以使用Google Chrome中的“Inspect”工具查看。)

将此更新的端点添加到URL将允许我们以编程方式指定页面。例如,要进入第6页,请使用以下命令:

https://www.cnet.com/search/?query=privacy&fq=&sort=1&p=6&typeName=&rpp=10


更新您的代码以使用此URL(在
&p=6
部分中指定页面)应该可以解决此问题。

是的,我刚刚意识到这就是问题所在,这与代码以及它如何选择页面有关,感谢您的帮助。。。如果我想让它搜索第1-100页,我会简单地创建一个循环并将代码放在其中吗?很乐意帮助!这应该行得通。我还建议在循环中休眠几毫秒,以避免对站点造成太大影响。
Searching: https://www.cnet.com/search/?query=privacy&page=3
news/the-circle-review-tom-hanks-emma-watson-tech-dave-eggers/
products/avg-privacy-glasses/preview/
news/amazon-reveals-its-newest-device-the-echo-look/
news/unroll-me-hit-with-privacy-suit-over-alleged-sale-of-user-data/
videos/tim-cook-almost-put-the-brakes-on-uber-over-privacy/
news/pause-pod-kickstarter-privacy-tent/
news/privacy-browser-brave-tor-trump/
news/microsoft-wants-you-to-trust-windows-10-privacy-again/
videos/what-is-vpn-explained-privacy-guide/
news/trump-signs-bill-repealing-us-internet-privacy-rules/
Header
'The Circle': A movie review for the tech literate
AVG Privacy Glasses
Amazon reveals the Echo Look, a device for style selfies
Unroll.me hit with privacy suit over alleged sale of user data
Tim Cook almost put the brakes on Uber over privacy
Hide from the world with your own pop-up privacy tent
Want true privacy? You need to check out this browser
Microsoft is fixing those confusing Windows 10 privacy messages
VPN explained: A privacy primer -- with robots and race cars
Trump signs bill repealing US internet privacy rules