How can I bypass a cookie agreement page while web scraping using Python?

前端 未结 1 1326
無奈伤痛
無奈伤痛 2021-01-20 23:01

I hurt my nose to a cookie agreement page...

What I am doing:

import requests
url = \"https://stockhouse.com/community/bullboards/\"
r = requests.get(url         


        
相关标签:
1条回答
  • 2021-01-20 23:46

    For this site it's enough to specify "dummy" cookie privacy-policy:

    import requests
    from bs4 import BeautifulSoup
    
    url = "https://stockhouse.com/community/bullboards/"
    
    cookies = {
        'privacy-policy': '1,XXXXXXXXXXXXXXXXXXXXXX'
    }
    
    r = requests.get(url, cookies=cookies)
    soup = BeautifulSoup(r.content, "html.parser")
    
    for h3 in soup.select('h3'):
        print(h3.get_text(strip=True))
    

    Prints the titles:

    Perfect timing: Mach offer no good as per AMF
    'Explosive' Move Up Next Week"
    Repsol/ Tullow
    Assessment
    $5.96
    Possible Deal?
    Massive Investor(s) Buys Over 1 Million JE Shares Last Close
    This CEO is really on the ball , right flubber
    slow bb
    Situation
    Loaffffdffffd
    Numerology of the number 36
    TIMBERRRR!!.. it will go down fast to $1.50
    Employees in the know do the right thing Whistelblow
    News finally
    Will be bought out...halt coming
    Green today
    Somebody is buying
    re re :350 mil is not enough
    And Trump fk up another day
    
    0 讨论(0)
提交回复
热议问题