Advertisement
Guest User

Leyla

a guest
Feb 20th, 2019
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. import requests
  2. from bs4 import BeautifulSoup as bs
  3. import re
  4. import pika
  5. import pymysql as mysql
  6. conn = mysql.connect(host="localhost", user="root", password="", db="crawl")
  7. cur = conn.cursor()
  8.  
  9. __author__ = "Leyla Agayeva"
  10.  
  11. url = "https://www.yellowpages.com/austin-tx/plumbers"
  12. req = requests.get(url)
  13. data = req.content
  14. soup = bs(data, "lxml")
  15. links = soup.findAll("div", {"class": "info"})
  16.  
  17. for link in links:
  18.     accepted = re.compile(r"^.*[0-9]\.")
  19.     if accepted.match(link.h2.text):
  20.         ddata = link.h2.text
  21.         print(ddata)
  22.         query = """INSERT INTO `info`(data) VALUES (%s)"""
  23.         cur.execute(query, ddata.strip())
  24.         conn.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement